﻿using WebLayer;
using System;
using System.Net;
using System.Diagnostics;
using System.IO;
using HtmlAgilityPack;
using WebParser;
using TableTypes;

class Program
{
    static void Main(string[] args)
    {
        Trace.Listeners.Add(new ConsoleTraceListener());

        /*LoginToken loginToken = new LoginToken("2448", "6181", "4001");
        loginToken.Language = Language.English;

        {
            CourseWebPage webPage = new CourseWebPage();
            webPage.LoginToken = loginToken;

            webPage.Request();

            string formatStr = "{0,-10} {1,-10} {2,-10} {3,-10}";
            Console.WriteLine(formatStr,
                                webPage.TableHeader.RowNumber,
                                webPage.TableHeader.Course,
                                webPage.TableHeader.Level,
                                webPage.TableHeader.Status);

            foreach (CourseTableEntry entry in webPage.TableContent)
            {
                Console.WriteLine(formatStr, entry.RowNumber,
                                            entry.Course,
                                            entry.Level,
                                            entry.Status);
            }
        }

        {
            ResultsWebPage webPage = new ResultsWebPage();
            webPage.LoginToken = loginToken;

            webPage.Request();

            string formatStr = "{0,-10} {1,-10} {2,-10} {3,-10} {4,-10} {5,-10} {6,-10}";
            Console.WriteLine(formatStr,
                                webPage.TableHeader.Course,
                                webPage.TableHeader.Unit,
                                webPage.TableHeader.Grammar,
                                webPage.TableHeader.Vocabulary,
                                webPage.TableHeader.Listening,
                                webPage.TableHeader.Reading,
                                webPage.TableHeader.Avarage);

            foreach (ResultsTableEntry entry in webPage.TableContent)
            {
                Console.WriteLine(formatStr,
                                 entry.Course,
                                 entry.Unit,
                                 entry.Grammar,
                                 entry.Vocabulary,
                                 entry.Listening,
                                 entry.Reading,
                                 entry.Avarage);
            }
        }

        {
            ClassesWebPage webPage = new ClassesWebPage();
            webPage.LoginToken = loginToken;

            webPage.Request();

            string formatStr = "{0,-12} {1,-8} {2,-15} {3,-15} {4,-25} {5,-10} {6,-10}";
            Console.WriteLine(formatStr,
                                webPage.AttendanceTableHeader.Presence,
                                webPage.AttendanceTableHeader.Date,
                                webPage.AttendanceTableHeader.Begin,
                                webPage.AttendanceTableHeader.End,
                                webPage.AttendanceTableHeader.Type,
                                webPage.AttendanceTableHeader.Course,
                                webPage.AttendanceTableHeader.Unit);

            foreach (ClassesTableEntry entry in webPage.AttendanceTableContent)
            {
                Console.WriteLine(formatStr,
                                 entry.Presence,entry.Date,entry.Begin,entry.End,
                                 entry.Type,entry.Course,entry.Unit);
            }

            Console.WriteLine();

            formatStr = "{0,-12} {1,-27} {2,-15} {3,-15} {4,-25} {5,-10} {6,-10}";

            Console.WriteLine(formatStr,
                                webPage.CancelledTableHeader.Presence,
                                webPage.CancelledTableHeader.Date,
                                webPage.CancelledTableHeader.Begin,
                                webPage.CancelledTableHeader.End,
                                webPage.CancelledTableHeader.Type,
                                webPage.CancelledTableHeader.Course,
                                webPage.CancelledTableHeader.Unit);

            foreach (ClassesTableEntry entry in webPage.CancelledTableContent)
            {
                Console.WriteLine(formatStr,
                                 entry.Presence, entry.Date, entry.Begin, entry.End,
                                 entry.Type, entry.Course, entry.Unit);
            }
        }

        {
            ReservationsWebPage webPage = new ReservationsWebPage();
            webPage.LoginToken = loginToken;

            webPage.Request();

            string formatStr = "{0,-27} {1,-60} {2,-15}";
            Console.WriteLine(formatStr,
                                webPage.ReservedTableHeader.Class,
                                webPage.ReservedTableHeader.Date,
                                webPage.ReservedTableHeader.Cancel);

            foreach (ReservedTableEntry entry in webPage.ReservedTableContent)
            {
                Console.WriteLine(formatStr, entry.Class, entry.Date, entry.Cancel);
            }

            Console.WriteLine();

            formatStr = "{0,-27} {1,-60}";

            Console.WriteLine(formatStr,
                                webPage.WaitListTableHeader.Class,
                                webPage.WaitListTableHeader.Date);

            foreach (WaitListTableEntry entry in webPage.WaitListTableContent)
            {
                Console.WriteLine(formatStr,
                                 entry.Class, entry.Date);
            }
        }

        {
            BookWebPage webPage = new BookWebPage();
            webPage.LoginToken = loginToken;

            webPage.Request();

            string formatStr = "{0,-30} {1,-25} {2,-25} {3,-10}";
            Console.WriteLine(formatStr,
                                webPage.TableHeader.Class,
                                webPage.TableHeader.Date,
                                webPage.TableHeader.Availability,
                                webPage.TableHeader.Book);

            foreach (BookClassesTableEntry entry in webPage.TableContent)
            {
                Console.WriteLine(formatStr, entry.Class,
                                            entry.Date,
                                            entry.Availability,
                                            entry.Book.Replace('\n',' ').Replace('\t',' '));
            }
        }
        */

       /* ClassName className1 = ClassName.ParseClassName("CC - GC 6 - RED");
        ClassName className2 = ClassName.ParseClassName("CC - GC 6 - VIOLET");           
        
        ClassName className3 = ClassName.ParseClassName("WS - GRAMMAR WORKSHOP");
        ClassName className4 = ClassName.ParseClassName("WS - CONVERSATION WORKSHOP");
        ClassName className5 = ClassName.ParseClassName("WS - WRITING WORKSHOP");
        ClassName className6 = ClassName.ParseClassName("WS - READING & VOCABULARY");

        ClassName className7 = ClassName.ParseClassName("CA - SPORT CLUB");


        Console.WriteLine(className1);
        Console.WriteLine(className2);
        Console.WriteLine(className3);
        Console.WriteLine(className4);
        Console.WriteLine(className5);
        Console.WriteLine(className6);
        Console.WriteLine(className7);

        ClassTime time1 = ClassTime.ParseBookEntry("Nov 10 2009 12:30 - 13:30");
        ClassTime time2 = ClassTime.ParseReservedEntry("Wednesday 11/11/2009 13:00 - 14:00");
        ClassTime time3 = ClassTime.ParseAttendedEntry("09-11-05", "09:00:00", "10:00:00");
        ClassTime time4 = ClassTime.ParseCancelledEntry("Oct 20 2009 12:00:00:000AM",
                                                            "08:30", "09:30");

        Console.WriteLine(time1);
        Console.WriteLine(time2);
        Console.WriteLine(time3);
        Console.WriteLine(time4);*/

        //File.WriteAllText("f:\\course.html", webPage.PageContent);
        LoginToken loginToken = new LoginToken("2448", "6181", "4001");
        
        BookTable table = BookTable.Fetch(loginToken);

        foreach (var a in table)
        {
            Console.WriteLine(a.ClassName + " " + a.ClassTime + " "+a.Available+" "+a.ClassId);
        }

        //LoginToken loginToken = new LoginToken("2448", "6181", "4001");
        WebPageCache cache = new WebPageCache();
        cache.LoginToken = loginToken;

        
        ReservedTable table1 = ReservedTable.Fetch(cache);
        Console.WriteLine();

        foreach (var a in table1)
        {
            Console.WriteLine(a.ClassName + " " + a.ClassTime + " " + a.ClassId);
        }

        
        WaitListTable table2 = WaitListTable.Fetch(cache);
        Console.WriteLine();

        foreach (var a in table2)
        {
            Console.WriteLine(a.ClassName + " " + a.ClassTime + " " + a.ClassId);
        }

        AttendanceTable table3 = AttendanceTable.Fetch(cache);
        Console.WriteLine();

        foreach (var a in table3)
        {
            Console.WriteLine(a.ClassName + " " + a.ClassTime + " " + a.Course + " " + a.Unit + " " + a.Present);
        }

        CancelledTable table4 = CancelledTable.Fetch(cache);
        Console.WriteLine();

        foreach (var a in table4)
        {
            Console.WriteLine(a.ClassName + " " + a.ClassTime + " " + a.Course + " " + a.Unit);
        }

    }
}

